import { IsNumber, IsString, IsBoolean, IsOptional, IsDate, ValidateNested } from "class-validator";
import { Type } from "class-transformer";
import { Gender } from "../../enum/gender.enum";

/**
 * 用户信息返回DTO（排除密码）
 */
export class UserResponseDto {
  @IsNumber({}, { message: "用户ID必须是数字" })
  id: number;

  @IsString({ message: "用户名必须是字符串" })
  username: string;

  @IsOptional()
  @IsBoolean({ message: "激活状态必须是布尔值" })
  isActive?: boolean;

  @IsOptional()
  @IsDate({ message: "创建时间必须是有效日期" })
  @Type(() => Date)
  createdAt?: Date;

  @IsOptional()
  @IsDate({ message: "更新时间必须是有效日期" })
  @Type(() => Date)
  updatedAt?: Date;

  @IsOptional()
  @ValidateNested({ message: "用户档案信息格式不正确" })
  @Type(() => UserProfileResponseDto)
  profile?: UserProfileResponseDto;

  @IsOptional()
  @ValidateNested({ each: true, message: "角色信息格式不正确" })
  @Type(() => RoleResponseDto)
  roles?: Array<RoleResponseDto>;
}

/**
 * 用户档案响应DTO
 */
export class UserProfileResponseDto {
  @IsNumber({}, { message: "档案ID必须是数字" })
  id: number;

  @IsString({ message: "性别必须是字符串" })
  gender: Gender;

  @IsString({ message: "头像必须是字符串" })
  photo: string;

  @IsString({ message: "邮箱必须是字符串" })
  email: string;

  @IsString({ message: "地址必须是字符串" })
  address: string;
}

/**
 * 角色响应DTO
 */
export class RoleResponseDto {
  @IsNumber({}, { message: "角色ID必须是数字" })
  id: number;

  @IsString({ message: "角色名称必须是字符串" })
  name: string;
}
